<?php

namespace Drupal\shusy_store_order_line\ViewsController;

use Drupal\shusy_store_order_line\ViewsController\handler\field\ShusyStoreOrderLineAmountTypeViewsField;
use Drupal\shusy_store_order_line\ViewsController\handler\field\ShusyStoreOrderLineAmountViewsField;
use Drupal\shusy_store_order_line\ViewsController\handler\field\ShusyStoreOrderLineEditLinkViewsField;
use Drupal\shusy_store_order_line\ViewsController\handler\field\ShusyStoreOrderLineStatusViewsField;
use Drupal\shusy_store_order_line\ViewsController\handler\field\ShusyStoreOrderLineTotalViewsField;
use Drupal\shusy_store_order_line\ViewsController\handler\field\ShusyStoreOrderLineTypeViewsField;
use Drupal\shusy_store_order_line\ViewsController\handler\filter\ShusyStoreOrderLineAmountTypeViewsFilter;
use Drupal\shusy_store_order_line\ViewsController\handler\filter\ShusyStoreOrderLineStatusViewsFilter;
use Drupal\shusy_store_order_line\ViewsController\handler\filter\ShusyStoreOrderLineTypeViewsFilter;
use EntityDefaultViewsController;


class ShusyStoreOrderLineViewsController extends EntityDefaultViewsController {

  public function views_data() {
    $data = parent::views_data();
    if (!empty($this->info['base table'])) {
      $table = $this->info['base table'];
      $info = [];

      $info[$table]['table'] = [
        'join' => [
          'shusy_store_order' => [
            'left_field' => 'id',
            'field' => 'store_order_id',
            'extra' => [
              [
                'field' => 'status',
                'value' => [1],
              ],
            ],
          ],
        ],
      ];

      $info[$table]['edit_link'] = [
        'title' => t('编辑'),
        'help' => t('编辑.'),
        'field' => [
          'handler' => ShusyStoreOrderLineEditLinkViewsField::class,
        ],
      ];
      $info[$table]['amount'] = [
        'title' => '单价',
        'help' => '单价',
        'real field' => 'amount',
        'field' => [
          'handler' => ShusyStoreOrderLineAmountViewsField::class,
        ],
      ];
      $info[$table]['total'] = [
        'title' => '总价',
        'help' => '总价',
        'real field' => 'total',
        'field' => [
          'handler' => ShusyStoreOrderLineTotalViewsField::class,
        ],
      ];
      $info[$table]['status'] = [
        'title' => '状态 0 禁用 1 启用',
        'help' => '状态 0 禁用 1 启用',
        'real field' => 'status',
        'field' => [
          'handler' => ShusyStoreOrderLineStatusViewsField::class,
        ],
        'filter' => [
          'handler' => ShusyStoreOrderLineStatusViewsFilter::class,
        ],
      ];

      $info[$table]['type'] = [
        'title' => '类型',
        'help' => '类型',
        'real field' => 'type',
        'field' => [
          'handler' => ShusyStoreOrderLineTypeViewsField::class,
        ],
        'filter' => [
          'handler' => ShusyStoreOrderLineTypeViewsFilter::class,
        ],
      ];
      $info[$table]['amount_type'] = [
        'title' => '类型 0 正常 1 VIP 2 店铺进货 3 拼团 4 秒杀',
        'help' => '类型 0 正常 1 VIP 2 店铺进货 3 拼团 4 秒杀',
        'real field' => 'amount_type',
        'field' => [
          'handler' => ShusyStoreOrderLineAmountTypeViewsField::class,
        ],
        'filter' => [
          'handler' => ShusyStoreOrderLineAmountTypeViewsFilter::class,
        ],
      ];

      $data = drupal_array_merge_deep($data, $info);
    }
    return $data;
  }
}
